package com.yunhe.abnormal.repository.data;

import com.yunhe.abnormal.domain.data.AbnormalEventRecordMeas;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface AbnormalEventRecordMeasRepository extends JpaRepository<AbnormalEventRecordMeas, Long> {
    /**
     * 查询全部异常事件记录
     *
     * @param spec     查询条件
     * @param pageable 分页对象
     */
    Page<AbnormalEventRecordMeas> findAll(Specification<AbnormalEventRecordMeas> spec, Pageable pageable);

    /**
     * 查询全部异常事件记录
     *
     * @param spec 查询条件
     * @param sort 排序对象
     */
    Iterable<AbnormalEventRecordMeas> findAll(Specification<AbnormalEventRecordMeas> spec, Sort sort);

    /**
     * 查询全部异常事件记录
     *
     * @param spec 查询条件
     */
    Iterable<AbnormalEventRecordMeas> findAll(Specification<AbnormalEventRecordMeas> spec);

    @Transactional
    @Modifying
    @Query(value = "delete from data_abnormal_record_meas where record_id=:recordId", nativeQuery=true)
    void deleteByRecordId(@Param("recordId") Long recordId);
}
